package org.locker.device.controller.admin;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.locker.common.idempotent.annotation.RepeatSubmit;
import org.locker.common.log.annotation.Log;
import org.locker.common.web.core.BaseController;
import org.locker.common.mybatis.core.page.PageQuery;
import org.locker.common.core.domain.R;
import org.locker.common.core.validate.AddGroup;
import org.locker.common.core.validate.EditGroup;
import org.locker.common.log.enums.BusinessType;
import org.locker.common.excel.utils.ExcelUtil;
import org.locker.domain.vo.ManagerFeesVo;
import org.locker.domain.bo.ManagerFeesBo;
import org.locker.service.IManagerFeesService;
import org.locker.common.mybatis.core.page.TableDataInfo;

/**
 * 代理商费用记录(场地)
 *
 * @author winnie
 * @date 2023-10-11
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/device/managerFees")
public class ManagerFeesController extends BaseController {

    private final IManagerFeesService managerFeesService;

    /**
     * 查询代理商费用记录(场地)列表
     */
    @SaCheckPermission("device:managerFees:list")
    @GetMapping("/list")
    public TableDataInfo<ManagerFeesVo> list(ManagerFeesBo bo, PageQuery pageQuery) {
        return managerFeesService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出代理商费用记录(场地)列表
     */
    @SaCheckPermission("device:managerFees:export")
    @Log(title = "代理商费用记录(场地)", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(ManagerFeesBo bo, HttpServletResponse response) {
        List<ManagerFeesVo> list = managerFeesService.queryList(bo);
        ExcelUtil.exportExcel(list, "代理商费用记录(场地)", ManagerFeesVo.class, response);
    }

    /**
     * 获取代理商费用记录(场地)详细信息
     *
     * @param managerFeesId 主键
     */
    @SaCheckPermission("device:managerFees:query")
    @GetMapping("/{managerFeesId}")
    public R<ManagerFeesVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long managerFeesId) {
        return R.ok(managerFeesService.queryById(managerFeesId));
    }

    /**
     * 新增代理商费用记录(场地)
     */
    @SaCheckPermission("device:managerFees:add")
    @Log(title = "代理商费用记录(场地)", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody ManagerFeesBo bo) {
        return toAjax(managerFeesService.insertByBo(bo));
    }

    /**
     * 修改代理商费用记录(场地)
     */
    @SaCheckPermission("device:managerFees:edit")
    @Log(title = "代理商费用记录(场地)", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody ManagerFeesBo bo) {
        return toAjax(managerFeesService.updateByBo(bo));
    }

    /**
     * 删除代理商费用记录(场地)
     *
     * @param managerFeesIds 主键串
     */
    @SaCheckPermission("device:managerFees:remove")
    @Log(title = "代理商费用记录(场地)", businessType = BusinessType.DELETE)
    @DeleteMapping("/{managerFeesIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] managerFeesIds) {
        return toAjax(managerFeesService.deleteWithValidByIds(List.of(managerFeesIds), true));
    }
}
